<?php
/**
 * @package model.dao
 * @author Sanu S <sanu@synergyquad.com>
 * @author Modified By Sanu S
 * @copyright Copyright &copy; 2011, synergyquad
 * @since 1.0 - May-18-2011
 * @version 1.1
 */


require_once 'vo/CompanyVO.php';
require_once 'vo/AttachmentVO.php';
require_once 'vo/NotificationVO.php';


class AssetDAOImpl
{
	
	/**
	 * @access public
	 * @staticvar Instance of MemberDAOImpl
	 */
	public static $_instance	= null;
	
	
	/**
	 * <p>Get an instance of MakeDAOImpl</p>
	 * 
	 * @access public
	 * @return MakeDAOImpl Instance of MakeDAOImpl
	 */
	public static function getInstance() 
	{
		if(self::$_instance == null) 
		{
			self::$_instance = new AssetDAOImpl();
		}
		
		return self::$_instance;
	}
	
        public function getStates()
        {
            $arrayCollection = null;
            $result_array = array();
            $query = "SELECT state, state_code FROM states";
            $result_data = mysql_query($query);
            while($row = mysql_fetch_object($result_data))
            {
                array_push($result_array, $row);
            }
                $arrayCollection = new ArrayCollection();
		$arrayCollection = $result_array;
		return $arrayCollection;
                
        }
        
        public function getCitiesByState($state_code)
        {
            $arrayCollection = null;
            $result_array = array();
            $query = "SELECT city,state_code FROM cities_extended WHERE state_code='".$state_code."'";
            $result_data = mysql_query($query);
            while($row = mysql_fetch_object($result_data))
            {
                array_push($result_array, $row);
            }
                $arrayCollection = new ArrayCollection();
		$arrayCollection = $result_array;
		return $arrayCollection;
        }
        
        
        
	public function getAssetByCat($start, $count, $asset_category) 
	{
		$arrayCollection = null;
		$where='';
		$arrayCollection = null;
                if($count<=0)
                    $limit= "";
                else 
                    $limit= " LIMIT ".$start.",".$count;
                    
                $query_data = "SELECT * FROM assets WHERE deleted=0 AND active=1 AND asset_category=".$asset_category.$limit;
		 
		/*if($searchKey)
			$where= "WHERE make LIKE '%".$searchKey."%' OR updated_by LIKE '%".$searchKey."%' OR created_by LIKE '%".$searchKey."%'";*/
                
		//$query_data.=$where."LIMIT ".$start.",".$count;
		
		$query_count = "SELECT COUNT(*) as count FROM assets WHERE deleted=0 AND active=1 AND asset_category=".$asset_category;
		$result_count = mysql_fetch_array(mysql_query($query_count));
		
		$result_data = mysql_query($query_data) or die($query_data);
		$result_array = array();
		while($row =  mysql_fetch_object($result_data))
		{
			array_push($result_array, $row);
		}
		
		$arrayCollection = new ArrayCollection();
		$arrayCollection->assets = $result_array;
		$arrayCollection->count = $result_count["count"];;
		
		return $arrayCollection;
	}
        
        public function getAllAssets()
        {
            $arrayCollection = null;
            
          /*  SELECT a.* FROM assets AS a  LEFT JOIN assets AS a2 ON a.asset_category = a2.asset_category GROUP BY a.asset_id HAVING COUNT(*) <= 4 ; */
            
           // $query_data = "SELECT * FROM assets GRUP LIMIT 0,5";
           // $query_data = "SELECT * FROM assets GRUP LIMIT 0,5";
          //  $query_count = "SELECT asset_category, COUNT(*) FROM assets GROUP BY asset_category";
            
        } 
		
		public function addAsset($assetVO) 
		{
			//var_dump($assetVO);
			
			$queryString = "INSERT INTO assets(`asset_id`,`asset_name`, `asset_datafield`,`asset_category`,`created_by`, `create_date`) VALUES(NULL,'".$assetVO->assetName."','".$assetVO->assetDataField."',".$assetVO->assetCategory.",'".$assetVO->createdBy."',now() )";
	
			$result = mysql_query($queryString) or die($queryString);
			return $result;

		}
		
		public function editAsset($assetVO) 
		{
		
			$queryString = "UPDATE assets SET asset_name='" .$assetVO->assetName. "', asset_datafield='" .$assetVO->assetDataField. "', updated_by='" .$assetVO->editedBy. "', update_date=now() WHERE asset_id=".$assetVO->assetID;

			$result = mysql_query($queryString) or die($queryString);
			return $result;
			
		}
		
		public function deleteAsset($assetID) 
		{
		
			$queryString = "UPDATE assets SET deleted=1 WHERE asset_id=".$assetID;

			$result = mysql_query($queryString) or die($queryString);
			return $result;
			
		}
		public function gettow_Status() 
		{
		 $arrayCollection = null;
            $result_array = array();
            $query = "SELECT * FROM vehicle_status Where status_category =2";
            $result_data = mysql_query($query);
            while($row = mysql_fetch_object($result_data))
            {
                array_push($result_array, $row);
            }
                $arrayCollection = new ArrayCollection();
		$arrayCollection = $result_array;
		return $arrayCollection;
		}
		
		
	
	
} 
?>